home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
CHASSIS_
/
READINTO.C
< prev
next >
Wrap
Text File
|
1992-05-14
|
2KB
|
38 lines
/************************************************************************************/
/* ReadIntoTE */
/* */
/* Reads open file into existing TextEdit record */
/************************************************************************************/
#include "MyHeaders.h"
long ReadIntoTE(int pathRefNum, TEHandle hTE)
{
long byteCount = 256; /* bytes requested / returned */
OSErr readErr; /* return from I/O routines */
long bytesRead = 0; /* total of bytes returned */
Ptr beginP; /* ptr to begin of temp I/O area */
Ptr nextP; /* ptr to next avail pos in I/O ara */
CursorSelect (NIL, NIL, watchCursor); /* set watch cursor */
readErr = SetFPos (pathRefNum, fsFromStart, 0); /* position file ptr to begin */
beginP = NewPtr(32767); /* get a temporary I/O area */
nextP = beginP; /* next avail pos is at top */
readErr = noErr; /* initialize before read loop */
while (readErr == noErr) /* read till error or EOF */
{
readErr = FSRead (pathRefNum, &byteCount, nextP); /* read a block */
bytesRead += byteCount; /* add bytes to total */
nextP += byteCount; /* reset nxt avail pos */
}
TESetText (beginP, bytesRead, hTE); /* copy into TE record */
TESetSelect (0, 0, hTE); /* set selection at top */
DisposPtr (beginP); /* release temporary I/O area */
return bytesRead; /* return total no of bytes */
}